<!DOCTYPE html>
<html class="iframe-h" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/css/admin.css}"/>

	</head>

	<body>
		<div class="wrap-container clearfix">
				<div class="column-content-detail">
					<form class="layui-form" action="">
						<div class="layui-form-item">
							<div class="layui-inline tool-btn">
								<button class="layui-btn layui-btn-small layui-btn-normal addParentBtn" data-url="/toDict"><i class="layui-icon">&#xe631;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="/toAddDictData"><i class="layui-icon">&#xe654;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-danger remove"  data-url="/removeDictData"><i class="layui-icon">&#xe640;</i></button>
								<button class="layui-btn layui-btn-small ayui-btn-normal modify"  data-url="/modifyDictData"><i class="layui-icon">&#xe614;</i></button>
							</div>
							<!--<div class="layui-inline">
								<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
							</div>-->

							<!--<button class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>-->
						</div>
					</form>
					<table class="layui-table" lay-data="{height: 'full', cellMinWidth: 80,  limit:15,limits:[15,30],
						url:'/dictDatas', page:true, id:'test'}" lay-filter="test" id="test">
						<thead>
						<tr>
							<th lay-data="{type:'checkbox'}">ID</th>
							<th lay-data="{field:'id',align:'center'}">id</th>
							<th lay-data="{field:'dictValue',align:'center'}">父字典值</th>
							<th lay-data="{field:'dictdataName', align:'center'}">字典名称</th>
							<th lay-data="{field:'dictdataValue', align:'center'}">字典值</th>
							<th lay-data="{field:'isfixed', align:'center',templet: '#checkboxTpl'}">状态</th>
						</tr>
						</thead>
					</table>

				</div>
		</div>


		<script th:src="@{/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/js/common.js}" type="text/javascript" charset="utf-8"></script>

		<script type="text/html" id="checkboxTpl">
			{{#  if(d.isfixed== 0){ }}
			不固定
			{{#  }else if(d.isfixed== 1){ }}
			固定
			{{#  }}}
		</script>
		<script>

            layui.config({
                base: '/js/module/'
            }).extend({
                dialog: 'dialog',
            });

			layui.use(['table','tree','jquery','dialog'], function() {
				var table = layui.table,
					form = layui.form,
                    $ = layui.jquery,
					tree = layui.tree,
                    dialog = layui.dialog;

                //获取当前iframe的name值
                var iframeObj = $(window.frameElement).attr('name');

				table.on('tool(test)', function(obj){
				});

                $('.addParentBtn').click(function() {
                    let url=$(this).attr('data-url');
                    //将iframeObj传递给父级窗口,执行操作完成刷新
                    page("数据字典分类列表", url, iframeObj, w = "800px", h = "720px");
                    return false;

                }).mouseenter(function() {

                    dialog.tips('数据字典分类列表', '.addParentBtn');

                });

                $('.modify').click(function() {
                    var checkStatus = table.checkStatus('test'),data = checkStatus.data;
                    if(data.length<1){
                        layer.msg("请选择一条记录")
                        return false;
                    }
                    if(data.length>1){
                        layer.msg("只能选择一条记录")
                        return false;
                    }
                    if(data[0].isfixed === 1){
                        layer.msg("固定不可修改！");
                        return false;
                    }
                    let url=$(this).attr('data-url');
                    url = url+"?id="+data[0].id;
                    //将iframeObj传递给父级窗口,执行操作完成刷新
                    page("设置", url, iframeObj, w = "700px", h = "620px");
                    return false;

                }).mouseenter(function() {

                    dialog.tips('设置', '.assign');

                });


                $('.remove').click(function() {
                    var checkStatus = table.checkStatus('test'),data = checkStatus.data;
                    if(data.length<1){
                        layer.msg("请选择一条记录")
                        return false;
                    }
                    if(data.length>1){
                        layer.msg("只能选择一条记录")
                        return false;
                    }
                    let url=$(this).attr('data-url');
                    if(data[0].isfixed === 1){
                        layer.msg("固定不可删除！");
                        return false;
                    }
                    layer.confirm( '您确定要删除选中项',function(index){
                            url = url+"?id="+data[0].id;
                            $.ajax({
                                url:url,
                                type: 'post',
                                dataType:'json',
                                success:function (data){
                                    let result = JSON.stringify(data.data);
                                    if(result === "true"){
                                        layer.close(index);
                                        layer.msg("删除成功");
                                        table.reload('test',{page:{curr:1}});
                                    }
                                }
                            });
                    });
                    return false;

                }).mouseenter(function() {

                    dialog.tips('删除', '.delBtn');

                })






            });

		</script>
	</body>

</html>